package com.nwpu.coursesupport.entity.bean;

import java.util.HashMap;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.nwpu.coursesupport.enumeration.StatusType;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class JSONResult {
	
	final static String FAIL="fail";
	
	private String statusCode;
	
	private String status;
	
	private String message;
	
	private HashMap data =new HashMap();

	public String getStatusCode() {
		return statusCode;
	}

	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public HashMap getData() {
		return data;
	}

	public void setData(HashMap data) {
		this.data = data;
	}
	
	public JSONResult success(){
		status=StatusType.SUCCESS.getName();
		statusCode=StatusType.SUCCESS.getStatusCode();
		return this;
	}
	
	public void login(){
		status=FAIL;
		statusCode=StatusType.NOLOGIN.getStatusCode();
		message=StatusType.NOLOGIN.getMessage();
	}
	public JSONResult login(String message){
		status=FAIL;
		statusCode=StatusType.NOLOGIN.getStatusCode();
		this.message=message;
		return this;
	}
	public void role(){
		status=FAIL;
		statusCode=StatusType.NOROLE.getStatusCode();
		message=StatusType.NOROLE.getMessage();
	}
	public JSONResult role(String message){
		status=FAIL;
		statusCode=StatusType.NOROLE.getStatusCode();
		this.message=message;
		return this;
	}
	
	public void fail(){
		status=FAIL;
		statusCode=StatusType.WRONG.getStatusCode();
	}
	public JSONResult fail(String message){
		this.fail();
		this.message=message;
		return this;
	}
	
	@SuppressWarnings("unchecked")
	public void addData(Object key, Object value){
		this.data.put(key, value);
	}
	
	public boolean isSuccess(){
		return status.equals(StatusType.SUCCESS.getName());
	}

	@Override
	public String toString() {
		return "JSONResult [statusCode=" + statusCode + ", status=" + status + ", message=" + message + ", data=" + data
				+ "]";
	}
	
}
